package com.example.huizhou.Service;


import com.example.huizhou.bean.Course;
import com.example.huizhou.mapper.CourseMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseService {
    @Autowired
    CourseMapper courseMapper;
    public List<Course> findAll()
    {
        List<Course> courses=courseMapper.findAll();
        return courses;
    }

    public List<Course> findcourse(String term)
    {
        List<Course> courses=courseMapper.findcourse(term);
        return courses;
    }
    public List<Course> findscourse(String term,String studentId)
    {
        List<Course> courses=courseMapper.findscourse(term,studentId);
        return courses;
    }

    public void delete(String studentid,String courseid)
    {
        courseMapper.delete(studentid,courseid);
    }

    public void insert(String studentid,String courseid)
    {
        courseMapper.insert(studentid, courseid);
    }

    public String year(String studentid)
    {
        String year=courseMapper.findyear(studentid);
        return year;
    }

    public List<Course> findocourse(String studentid,String courseid)
    {
        List<Course> courses=courseMapper.findocourse(studentid,courseid);
        return courses;
    }
    //教师端使用
    public List<Course> findcourse_th(String classify,String teacher){
        List<Course> courses_th=courseMapper.findcourse_th(classify,teacher);
        return courses_th;
    }
    public String find_cname(int course_id){
        return courseMapper.find_cname(course_id);
    }
    public int up_course(int cid,String cname,int clength,int cscore,String time,String csite,int cnumber,String classify,String cteacher,String cterm){
        if(courseMapper.find_cid(cid).size()!=0){
            return 1;
        }
        else if(courseMapper.find_time(time,cteacher,cterm).size()!=0){
            return 2;
        }
        else{
            courseMapper.up_course(cid,cname,clength,cscore,time,csite,cnumber,classify,cteacher,cterm);
            return 0;
        }
    }
    public int modify_course(int cid,String cname,int clength,int cscore,String time,String csite,int cnumber,String classify,String cteacher,String cterm){
        if(courseMapper.find_mtime(time,cteacher,cid,cterm).size()!=0){
            return 2;
        }
        else{
            courseMapper.modify_course(cid,cname,clength,cscore,time,csite,cnumber,classify,cterm);
            return 0;
        }
    }
    public void delete_course(int courseid){
        courseMapper.delete_course(courseid);
    }
}
